home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the 3D Game Programming Gurus / gurus.iso / DirectX / dx9sdkcp.exe / SDK (C++) / Samples / Media / DolphinTween2.vsh < prev    next >
Encoding:
Text File  |  2002-11-12  |  2.4 KB  |  82 lines

  1. ;------------------------------------------------------------------------------
  2. ; Constants specified by the app
  3. ;    c0      = ( 0, 0, 0, 0 )
  4. ;    c1      = ( 1, 0.5, 2, 4 )
  5. ;    c2      = ( fWeight1, fWeight2, fWeight3, 0 )
  6. ;    c4-c7   = matWorldViewProjection
  7. ;    c8-c11  = matWorldView
  8. ;    c19     = light direction (in model space)
  9. ;    c21     = material diffuse color * light diffuse color
  10. ;    c22     = material ambient color
  11. ;
  12. ; Vertex components (as specified in the vertex DECL)
  13. ;    v0    = Position
  14. ;    v3    = Normal
  15. ;    v6    = Texcoords
  16. ;------------------------------------------------------------------------------
  17. vs.1.1
  18.  
  19. dcl_position0 v0
  20. dcl_position1 v1
  21. dcl_position2 v2
  22. dcl_normal0   v3
  23. dcl_normal1   v4
  24. dcl_normal2   v5
  25. dcl_texcoord0 v6
  26.  
  27. ;------------------------------------------------------------------------------
  28. ; Vertex transformation
  29. ;------------------------------------------------------------------------------
  30.  
  31. ; Tween the 3 positions (v0,v1,v2) into one position
  32. mul r0, v0, c2.x
  33. mul r1, v1, c2.y
  34. mul r2, v2, c2.z
  35. add r3, r0, r1
  36. add r3, r3, r2
  37.  
  38. ; Transform position to the clipping space
  39. m4x4 oPos, r3, c4
  40.  
  41. ; Transform position to the camera space
  42. m4x4 r9, r3, c8
  43.  
  44. ;------------------------------------------------------------------------------
  45. ; Lighting calculation
  46. ;------------------------------------------------------------------------------
  47.  
  48. ; Tween the 3 normals (v3,v4,v5) into one normal
  49. mul r0, v3, c2.x
  50. mul r1, v4, c2.y
  51. mul r2, v5, c2.z
  52. add r3, r0, r1
  53. add r3, r3, r2
  54.  
  55. ; Do the lighting calculation
  56. dp3 r1.x, r3, c19    ; r1 = normal dot light
  57. max r1.x, r1.x, c0.x   ; if dot < 0 then dot = 0
  58. mul r0, r1.x, c21    ; Multiply with diffuse
  59. add r0, r0, c22      ; Add in ambient
  60. min oD0, r0, c1.x    ; clamp if > 1
  61.  
  62.  
  63. ;------------------------------------------------------------------------------
  64. ; Texture coordinates
  65. ;------------------------------------------------------------------------------
  66.  
  67. ; Gen tex coords from vertex xz position
  68. mul oT0.xy, c1.y, r9.xz
  69.  
  70. ;------------------------------------------------------------------------------
  71. ; Fog calculation
  72. ;------------------------------------------------------------------------------
  73.  
  74. ; compute fog factor f = (fog_end - dist)*(1/(fog_end-fog_start))
  75. add r0.x, -r9.z, c23.y
  76. mul r0.x, r0.x, c23.z
  77. max r0.x, r0.x, c0.x       ; clamp fog to > 0.0
  78. min oFog, r0.x, c1.x     ; clamp fog to < 1.0
  79.  
  80.  
  81.  
  82.